<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>login</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript">
		var cur_path = "<%=request.getContextPath() %>";
	</script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.js"></script>
	 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/bootstrap/css/bootstrap.css"/>
	 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/bootstrap/css/bootstrap-responsive.css"/>
	 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/theme.css"/> 
	<script type="text/javascript">
		window.onload=function(){
			window.document.onkeydown=function(e){
			try{
				if(event.keyCode){
					if(event.keyCode==13){
	                	document.getElementById("btn_login").click();   
	                	return false;
	                }
				}
			}catch(e){}
			try{
				if(e.which){
					if(e.which ==13){
	                	document.getElementById("btn_login").click();   
	                	return false;
	                }
				}
			}catch(e){}
			};
		
			$('#imageCode').bind('click', function(){ 
				var ls_url = cur_path + "/login.do?method=getImg&data="+new Date();
		        $("#imageCode").removeAttr("src"); //去除
		        $("#imageCode").attr("src",ls_url);
		     }); 
		};
		function checkAccount(){
			var userid = $("#userid").val();
			if(userid==""){
				$("#error_msg").text("用户名不能为空！");
				$("#userid").focus();
				return false;
			}
			var password = $("#password").val();
			if(password==""){
				$("#error_msg").text("密码不能为空！");
				$("#password").focus();
				return false;
			}
			var code = $("#code").val();
			if(code==""){
				$("#error_msg").text("验证码不能为空！");
				$("#code").focus();
				return false;
			}
			var ls_url = cur_path + "/login.do?method=checkCode&code="+code;
			$.post(ls_url,function(data){
				data = eval("["+data+"]");
				var return_code = data[0].return_code;
				if(return_code=='ok'){
					$.get( cur_path + "/login.do?method=login&userId="+$("#userid").val()+"&passWord="+$("#password").val()+"&d="+new Date(),function (data1){
						data = eval("["+data1+"]");
						return_code = data[0].return_code;
						if(return_code!='ok'){
							$("#error_msg").html("用户名密码错误！");
						}else{
							window.location.href=cur_path + "/index.jsp";
						}
					});
				}else{
					$("#error_msg").html("验证码错误");
					$("#code").focus();
					return  false;
				}
			});
		}
		
		function login(){
			checkAccount();
		}
		
	</script>
  </head>
  
  <body style="margin: 0 auto;margin-top: 3px">
<%--   <center style="vertical-align: middle;">
  <div>
  	<form name="form1" action="base/loginAction_login.do" method="post">
    	<table align="center" >
    	<tr>
    		<td colspan="3" style="text-align: center; font-weight: bold;">
    		超市管理系统登录</td>
    	</tr>
    		<tr >
    			<td>账号:</td>
    			<td colspan="2">
    				<input type="text" name="userid" id="userid" style="width: 200px;" />
    			</td>
    		</tr>
    		<tr>
    			<td>密码:</td>
    			<td colspan="2">
    				<input type="password" name="password" id="password" style="width: 200px;" />
    			</td>
    		</tr>
    		<tr>
    			<td>验证码:</td>
    			<td>
    				<input type="text" name="code" id="code" style="width: 80px;" />
    			</td>
    			<td>
    				<img align='left' src="<%=request.getContextPath() %>/login.do?method=getImg" height="25" width="60"
					 name="imageCode" id="imageCode" title="看不清？点击换一张！" style="float:left;vertical-align:middle;"/>
    			</td>
    		</tr>
    		<tr>
    			<td colspan="3" align="center">
    				<button type="button" id="btn_login" onclick="login()" style="width: 100px;">登录</button>
    				<button type="button" id="btn_login" onclick="window.location.href='<%=request.getContextPath() %>/Users.jsp?sign=sign'" style="width: 100px;">注册</button>
    			</td>
    		</tr>
    		<tr>
    			<td colspan="3" align="center">
    				<span style="color: red;" id="error_msg"><%=request.getAttribute("Usersmsg")==null?"":request.getAttribute("Usersmsg").toString() %></span>
    			</td>
    		</tr>
    	</table>
    </form>
    </div>
    </center>
 --%>    
    <div class="navbar">
        <div class="navbar-inner">
            <div class="container-fluid" style="text-align:center;">

                <a class="brand" href="javascript:void(0)" style="width: 100%"><span style="color:white; ;">在线点餐系统</span></a>
            </div>
        </div>
    </div>
        <div class="row-fluid">
    <div class="dialog span4">
        <div class="block">
            <div class="block-heading">用户登录</div>
            <div class="block-body">
                <form>
                    <label>帐号:</label>
                     <input type="text"  class="span12" name="userid" id="userid"  />
                    <label>密码:</label>
                    <input type="password" class="span12" name="password" id="password"/>
                    <a href="javascript:login()" onclick="login()"  class="btn btn-primary pull-left">登录</a>
                   <a href="javascript:void(0)" onclick="window.location.href='<%=request.getContextPath() %>/Users.jsp?sign=sign'"  class="btn btn-primary pull-right">注册</a>                  
                    <div class="clearfix"></div>
               </form>
            </div>
        </div>

    </div>    
    
 </div>   
  </body>
</html>
